package cn.kgc.kgde.bookstore.controller;


import cn.kgc.kgde.bookstore.dto.EvaluationDTO;
import cn.kgc.kgde.bookstore.entity.Evaluation;

import cn.kgc.kgde.bookstore.entity.ResultInfo;
import cn.kgc.kgde.bookstore.service.EvaluationService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author myt
 * @since 2022-05-23
 */
@CrossOrigin
@RestController
@RequestMapping("/evaluation")
public class EvaluationController {
    @Autowired
    private EvaluationService evaluationService;

    //添加评论
    @PostMapping("/addEvaluation")
    public ResultInfo addEvaluation(Evaluation evaluation){
        this.evaluationService.save(evaluation);
        return new ResultInfo(200,"添加成功",evaluation);
    }
    //删除评论
    @DeleteMapping("/deleteEvaluation")
    public ResultInfo deleteEvaluation(Evaluation evaluation){
        this.evaluationService.removeById(evaluation.getEvaluationId());
        return new ResultInfo(200,"删除成功");
    }

    //查询某一件商品的评论
    @GetMapping("selectEvaluation")
    public ResultInfo selectEvaluation(Long bookId){
        IPage<EvaluationDTO> evaluationDTOIPage = this.evaluationService.evaluationList(bookId);
        return new ResultInfo(200,"查询成功",evaluationDTOIPage);
    }
}
